﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

#region License
/*
 *  Copyright (c) Dumuzi.cn 2009 , All rights reserved.
 *  CLR Version: 2.0.50727.4927
 *  NameSpace: Summer.IO
 *  Author:Edwin Tai,戴佳顺
 *  Msn:edwin19861218@hotmail.com
 *  QQ: 1961218
 *  Date:2009-11-16 15:02:04
 *  Licensed under the Microsoft Public License (Ms-PL)
 *  This license governs use of the accompanying software. 
 *  If you use the software, you accept this license.
 *  If you do not accept the license, do not use the software.
 */
#endregion

namespace Summer.IO
{
    /// <summary>
    /// Define some methods about string
    /// In order to operate string easier
    /// </summary>
    public static class StringManagement
    {
        public static string[] ToArray(this string s)
        {
            return new string[] { s };
        }
        /// <summary>
        /// Get StringJoiner by string
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static StringJoiner ToStringJoiner(this string str)
        {
            StringJoiner s = str;
            return s;
        }
        /// <summary>
        /// The class is to implement a simply StringBuilder
        /// </summary>
        public class StringJoiner
        {
            protected StringBuilder m_builder;

            public StringJoiner()
            {
                m_builder = new StringBuilder();
            }
            /// <summary>
            /// Implicit conversion to StringJoiner from string
            /// </summary>
            /// <param name="value"></param>
            /// <returns></returns>
            public static implicit operator StringJoiner(string value)
            {
                StringJoiner text = new StringJoiner();
                text.m_builder.Append(value);
                return text;
            }
            /// <summary>
            /// Add overrde
            /// </summary>
            /// <param name="self"></param>
            /// <param name="value"></param>
            /// <returns></returns>
            public static StringJoiner operator +(StringJoiner self, string value)
            {
                self.m_builder.Append(value);
                return self;
            }
            public static StringJoiner operator +(StringJoiner self, object value)
            {
                self.m_builder.Append(value);
                return self;
            }
            public static implicit operator string(StringJoiner value)
            {
                return value.ToString();
            }
            /// <summary>
            ///  Implicit conversion to string from StringJoiner
            /// </summary>
            /// <returns></returns>
            public override string ToString()
            {
                return this.m_builder.ToString();
            }
        }

    }
}
